Command Query Separation (CQS)

Description:

CQS checks that methods that return a value do not modify the state of the declaring object. The methods used to query the state of an object must be different from the methods used to perform commands (change the state of the object).

Incorrect:

    private
      size:integer;
...    
    function Grow(delta:integer):integer;
    begin
        size := size + delta;
        
        ...
        
        result := size;
    end;

Correct:

    procedure Grow(delta:Integer);
    begin
        size := size + delta;
        
        ...
    end;

   function Size():integer;
    begin
        result := size;
    end;

Refactoring: